import 'package:flutter/material.dart';

/// 应用常量配置
/// App constants configuration
class AppConstants {
  // 私有构造函数，防止实例化
  // Private constructor to prevent instantiation
  AppConstants._();

  // ==================== 应用信息 App Information ====================

  /// 应用名称
  /// App name
  static const String appName = '情绪记录疗愈';

  /// 应用版本
  /// App version
  static const String appVersion = '1.0.0';

  /// 应用包名
  /// App package name
  static const String packageName = 'com.example.emotion_healing';

  /// 调试模式标志
  /// Debug mode flag
  static const bool isDebugMode = true;

  /// 获取设备类型
  /// Get device type based on screen width
  static String getDeviceType(double screenWidth) {
    if (screenWidth < 600) {
      return 'mobile';
    } else if (screenWidth < 1200) {
      return 'tablet';
    } else {
      return 'desktop';
    }
  }

  // ==================== 间距常量 Spacing Constants ====================

  /// 超小间距
  /// Extra small spacing
  static const double spacingXS = 4.0;

  /// 小间距
  /// Small spacing
  static const double spacingS = 8.0;
  static const double spacingSmall = 8.0; // 别名

  /// 中等间距
  /// Medium spacing
  static const double spacingM = 16.0;
  static const double spacingMedium = 16.0; // 别名

  /// 大间距
  /// Large spacing
  static const double spacingL = 24.0;
  static const double spacingLarge = 24.0; // 别名

  /// 超大间距
  /// Extra large spacing
  static const double spacingXL = 32.0;

  /// 间距 - 超大别名
  /// Spacing - extra large alias
  static const double spacingXLarge = spacingXL;

  /// 超超大间距
  /// Extra extra large spacing
  static const double spacingXXL = 48.0;

  // ==================== 边距常量 Padding Constants ====================

  /// 页面水平边距
  /// Page horizontal padding
  static const EdgeInsets pageHorizontalPadding =
      EdgeInsets.symmetric(horizontal: spacingM);

  /// 页面垂直边距
  /// Page vertical padding
  static const EdgeInsets pageVerticalPadding =
      EdgeInsets.symmetric(vertical: spacingM);

  /// 页面全边距
  /// Page all padding
  static const EdgeInsets pageAllPadding = EdgeInsets.all(spacingM);

  /// 小边距 (double values for EdgeInsets.all())
  /// Small padding (double values for EdgeInsets.all())
  static const double paddingSmall = spacingS;

  /// 中等边距 (double values for EdgeInsets.all())
  /// Medium padding (double values for EdgeInsets.all())
  static const double paddingMedium = spacingM;

  /// 大边距 (double values for EdgeInsets.all())
  /// Large padding (double values for EdgeInsets.all())
  static const double paddingLarge = spacingL;

  /// EdgeInsets 小边距
  /// EdgeInsets small padding
  static const EdgeInsets paddingSmallInsets = EdgeInsets.all(spacingS);

  /// EdgeInsets 中等边距
  /// EdgeInsets medium padding
  static const EdgeInsets paddingMediumInsets = EdgeInsets.all(spacingM);

  /// EdgeInsets 大边距
  /// EdgeInsets large padding
  static const EdgeInsets paddingLargeInsets = EdgeInsets.all(spacingL);

  /// 卡片内边距
  /// Card padding
  static const EdgeInsets cardPadding = EdgeInsets.all(spacingM);

  /// 按钮内边距
  /// Button padding
  static const EdgeInsets buttonPadding = EdgeInsets.symmetric(
    horizontal: spacingL,
    vertical: spacingS,
  );

  /// 输入框内边距
  /// Input padding
  static const EdgeInsets inputPadding = EdgeInsets.symmetric(
    horizontal: spacingM,
    vertical: spacingS,
  );

  /// 列表项内边距
  /// List item padding
  static const EdgeInsets listItemPadding = EdgeInsets.symmetric(
    horizontal: spacingM,
    vertical: spacingS,
  );

  // ==================== 圆角常量 Border Radius Constants ====================

  /// 小圆角
  /// Small border radius
  static const double radiusS = 8.0;

  /// 中等圆角
  /// Medium border radius
  static const double radiusM = 12.0;

  /// 大圆角
  /// Large border radius
  static const double radiusL = 16.0;

  /// 超大圆角
  /// Extra large border radius
  static const double radiusXL = 20.0;

  /// 中等圆角别名
  /// Medium border radius alias
  static const double radiusMedium = radiusM;

  /// 小圆角别名
  /// Small border radius alias
  static const double radiusSmall = radiusS;

  /// 大圆角别名
  /// Large border radius alias
  static const double radiusLarge = radiusL;

  /// 圆形
  /// Circular
  static const double radiusCircular = 50.0;

  // ==================== 尺寸常量 Size Constants ====================

  /// 图标尺寸 - 小
  /// Icon size - small
  static const double iconSizeS = 16.0;

  /// 图标尺寸 - 中等
  /// Icon size - medium
  static const double iconSizeM = 24.0;

  /// 图标尺寸 - 大
  /// Icon size - large
  static const double iconSizeL = 32.0;

  /// 图标尺寸 - 超大
  /// Icon size - extra large
  static const double iconSizeXL = 48.0;

  /// 图标尺寸 - 小别名
  /// Icon size - small alias
  static const double iconSizeSmall = iconSizeS;

  /// 图标尺寸 - 中等别名
  /// Icon size - medium alias
  static const double iconSizeMedium = iconSizeM;

  /// 头像尺寸 - 小
  /// Avatar size - small
  static const double avatarSizeS = 32.0;

  /// 头像尺寸 - 中等
  /// Avatar size - medium
  static const double avatarSizeM = 48.0;

  /// 头像尺寸 - 大
  /// Avatar size - large
  static const double avatarSizeL = 64.0;

  /// 按钮高度 - 小
  /// Button height - small
  static const double buttonHeightS = 32.0;

  /// 按钮高度 - 中等
  /// Button height - medium
  static const double buttonHeightM = 48.0;

  /// 按钮高度 - 大
  /// Button height - large
  static const double buttonHeightL = 56.0;

  /// 输入框高度
  /// Input field height
  static const double inputHeight = 48.0;

  /// 应用栏高度
  /// App bar height
  static const double appBarHeight = 56.0;

  /// 底部导航栏高度
  /// Bottom navigation bar height
  static const double bottomNavHeight = 60.0;

  /// 底部导航栏高度别名
  /// Bottom navigation bar height alias
  static const double bottomNavigationHeight = 60.0;

  /// 浮动操作按钮尺寸
  /// Floating action button size
  static const double fabSize = 56.0;

  /// 卡片最小高度
  /// Card minimum height
  static const double cardMinHeight = 80.0;

  /// 列表项高度
  /// List item height
  static const double listItemHeight = 56.0;

  // ==================== 动画常量 Animation Constants ====================

  /// 快速动画时长
  /// Fast animation duration
  static const Duration animationFast = Duration(milliseconds: 150);

  /// 中等动画时长
  /// Medium animation duration
  static const Duration animationMedium = Duration(milliseconds: 300);

  /// 慢速动画时长
  /// Slow animation duration
  static const Duration animationSlow = Duration(milliseconds: 500);

  /// 页面过渡动画时长
  /// Page transition animation duration
  static const Duration pageTransitionDuration = Duration(milliseconds: 250);

  /// 对话框动画时长
  /// Dialog animation duration
  static const Duration dialogAnimationDuration = Duration(milliseconds: 200);

  /// 底部表单动画时长
  /// Bottom sheet animation duration
  static const Duration bottomSheetAnimationDuration =
      Duration(milliseconds: 250);

  /// 加载动画时长
  /// Loading animation duration
  static const Duration loadingAnimationDuration = Duration(milliseconds: 1000);

  // ==================== 阴影常量 Shadow Constants ====================

  /// 轻微阴影
  /// Light shadow
  static const List<BoxShadow> shadowLight = [
    BoxShadow(
      color: Color(0x0F000000),
      blurRadius: 4,
      offset: Offset(0, 2),
    ),
  ];

  /// 中等阴影
  /// Medium shadow
  static const List<BoxShadow> shadowMedium = [
    BoxShadow(
      color: Color(0x1A000000),
      blurRadius: 8,
      offset: Offset(0, 4),
    ),
  ];

  /// 重阴影
  /// Heavy shadow
  static const List<BoxShadow> shadowHeavy = [
    BoxShadow(
      color: Color(0x26000000),
      blurRadius: 16,
      offset: Offset(0, 8),
    ),
  ];

  /// 果冻质感阴影
  /// Jelly-like shadow
  static const List<BoxShadow> shadowJelly = [
    BoxShadow(
      color: Color(0x1A000000),
      blurRadius: 12,
      offset: Offset(0, 6),
      spreadRadius: 2,
    ),
  ];

  /// 柔和阴影
  /// Soft shadow
  static const List<BoxShadow> shadowSoft = [
    BoxShadow(
      color: Color(0x0A000000),
      blurRadius: 6,
      offset: Offset(0, 3),
    ),
  ];

  // ==================== 网格常量 Grid Constants ====================

  /// 网格列数 - 手机
  /// Grid column count - phone
  static const int gridColumnCountPhone = 2;

  /// 网格列数 - 平板
  /// Grid column count - tablet
  static const int gridColumnCountTablet = 3;

  /// 网格间距
  /// Grid spacing
  static const double gridSpacing = spacingS;

  /// 网格纵横比
  /// Grid aspect ratio
  static const double gridAspectRatio = 1.2;

  // ==================== 断点常量 Breakpoint Constants ====================

  /// 手机断点
  /// Phone breakpoint
  static const double breakpointPhone = 600;

  /// 平板断点
  /// Tablet breakpoint
  static const double breakpointTablet = 900;

  /// 桌面断点
  /// Desktop breakpoint
  static const double breakpointDesktop = 1200;

  // ==================== 数据库常量 Database Constants ====================

  /// 数据库名称
  /// Database name
  static const String databaseName = 'emotion_healing.db';

  /// 数据库版本
  /// Database version
  static const int databaseVersion = 1;

  /// 分页大小
  /// Page size
  static const int pageSize = 20;

  /// 最大文件大小 (10MB)
  /// Maximum file size (10MB)
  static const int maxFileSize = 10 * 1024 * 1024;

  /// 最大日记长度
  /// Maximum diary length
  static const int maxDiaryLength = 1000;

  // ==================== 情绪相关常量 Emotion Related Constants ====================

  /// 情绪强度最小值
  /// Minimum emotion intensity
  static const int minEmotionIntensity = 1;

  /// 情绪强度最大值
  /// Maximum emotion intensity
  static const int maxEmotionIntensity = 10;

  /// 默认情绪强度
  /// Default emotion intensity
  static const int defaultEmotionIntensity = 5;

  /// 日记最大字符数
  /// Maximum diary characters
  static const int maxDiaryCharacters = 5000;

  /// 日记最小字符数
  /// Minimum diary characters
  static const int minDiaryCharacters = 1;

  // ==================== 媒体文件常量 Media File Constants ====================

  /// 支持的图片格式
  /// Supported image formats
  static const List<String> supportedImageFormats = [
    'jpg',
    'jpeg',
    'png',
    'gif',
    'webp',
  ];

  /// 支持的音频格式
  /// Supported audio formats
  static const List<String> supportedAudioFormats = [
    'mp3',
    'wav',
    'aac',
    'm4a',
  ];

  /// 最大录音时长（秒）
  /// Maximum recording duration (seconds)
  static const int maxRecordingDuration = 300; // 5分钟

  /// 图片压缩质量
  /// Image compression quality
  static const int imageCompressionQuality = 80;

  /// 图片最大宽度
  /// Maximum image width
  static const int maxImageWidth = 1920;

  /// 图片最大高度
  /// Maximum image height
  static const int maxImageHeight = 1080;

  // ==================== 通知常量 Notification Constants ====================

  /// 默认通知时间
  /// Default notification time
  static const TimeOfDay defaultNotificationTime =
      TimeOfDay(hour: 20, minute: 0);

  /// 通知渠道ID
  /// Notification channel ID
  static const String notificationChannelId = 'emotion_reminder';

  /// 通知渠道名称
  /// Notification channel name
  static const String notificationChannelName = '情绪提醒';

  /// 通知渠道描述
  /// Notification channel description
  static const String notificationChannelDescription = '用于提醒用户记录情绪';

  // ==================== 分析常量 Analytics Constants ====================

  /// 趋势分析默认天数
  /// Default days for trend analysis
  static const int defaultTrendDays = 30;

  /// 词云最大词数
  /// Maximum words in word cloud
  static const int maxWordCloudWords = 50;

  /// 词云最小词频
  /// Minimum word frequency for word cloud
  static const int minWordFrequency = 2;

  /// 图表动画时长
  /// Chart animation duration
  static const Duration chartAnimationDuration = Duration(milliseconds: 800);

  // ==================== 设置常量 Settings Constants ====================

  /// 默认语言
  /// Default language
  static const String defaultLanguage = 'zh';

  /// 支持的语言
  /// Supported languages
  static const List<String> supportedLanguages = ['zh', 'en'];

  /// 默认字体大小倍数
  /// Default font size multiplier
  static const double defaultFontSizeMultiplier = 1.0;

  /// 字体大小倍数范围
  /// Font size multiplier range
  static const double minFontSizeMultiplier = 0.8;
  static const double maxFontSizeMultiplier = 1.5;

  // ==================== 错误消息常量 Error Message Constants ====================

  /// 网络错误消息
  /// Network error message
  static const String networkErrorMessage = '网络连接失败，请检查网络设置';

  /// 数据库错误消息
  /// Database error message
  static const String databaseErrorMessage = '数据库操作失败，请重试';

  /// 文件操作错误消息
  /// File operation error message
  static const String fileErrorMessage = '文件操作失败，请重试';

  /// 权限错误消息
  /// Permission error message
  static const String permissionErrorMessage = '权限不足，请在设置中开启相关权限';

  /// 未知错误消息
  /// Unknown error message
  static const String unknownErrorMessage = '发生未知错误，请重试';

  // ==================== 成功消息常量 Success Message Constants ====================

  /// 保存成功消息
  /// Save success message
  static const String saveSuccessMessage = '保存成功';

  /// 删除成功消息
  /// Delete success message
  static const String deleteSuccessMessage = '删除成功';

  /// 更新成功消息
  /// Update success message
  static const String updateSuccessMessage = '更新成功';

  /// 导出成功消息
  /// Export success message
  static const String exportSuccessMessage = '导出成功';

  /// 导入成功消息
  /// Import success message
  static const String importSuccessMessage = '导入成功';

  // ==================== 工具方法 Utility Methods ====================

  /// 根据屏幕宽度获取网格列数
  /// Get grid column count by screen width
  static int getGridColumnCount(double screenWidth) {
    if (screenWidth < breakpointPhone) {
      return gridColumnCountPhone;
    } else if (screenWidth < breakpointTablet) {
      return gridColumnCountTablet;
    } else {
      return gridColumnCountTablet + 1;
    }
  }

  /// 判断是否为手机设备
  /// Check if device is phone
  static bool isPhone(double screenWidth) {
    return screenWidth < breakpointPhone;
  }

  /// 判断是否为平板设备
  /// Check if device is tablet
  static bool isTablet(double screenWidth) {
    return screenWidth >= breakpointPhone && screenWidth < breakpointDesktop;
  }

  /// 判断是否为桌面设备
  /// Check if device is desktop
  static bool isDesktop(double screenWidth) {
    return screenWidth >= breakpointDesktop;
  }

  /// 获取响应式间距
  /// Get responsive spacing
  static double getResponsiveSpacing(double screenWidth) {
    if (isPhone(screenWidth)) {
      return spacingS;
    } else if (isTablet(screenWidth)) {
      return spacingM;
    } else {
      return spacingL;
    }
  }

  /// 获取响应式边距
  /// Get responsive padding
  static EdgeInsets getResponsivePadding(double screenWidth) {
    final spacing = getResponsiveSpacing(screenWidth);
    return EdgeInsets.all(spacing);
  }
}
